package com.banana.manager.forest.service.impl.handle;

import com.banana.manager.forest.dao.handle.IDiscussDao;
import com.banana.manager.forest.dao.handle.IRecordDao;
import com.banana.manager.forest.entity.handle.DiscussBean;
import com.banana.manager.forest.entity.handle.RecordBean;
import com.banana.manager.forest.service.iihandle.IDiscussService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional
public class DiscussServiceImpl implements IDiscussService {

    @Resource
    private IRecordDao recordDao;

    @Resource
    private IDiscussDao discussDao;

    @Override
    public DiscussBean addDiscuss(Integer recordId, DiscussBean discussBean) {
        discussDao.insert(discussBean);
        RecordBean recordBean = recordDao.selectById(recordId);
        recordBean.setRecordAdvice(discussBean.getDiscussResult());
        recordDao.updateById(recordBean);
        discussDao.addDiscuss(recordId,discussBean.getDiscussId());
        return discussDao.selectById(discussBean.getDiscussId());
    }

    @Override
    public List<RecordBean> FindAllDiscuss() {
        QueryWrapper<RecordBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_stage","无法解决，申请专家会商");
        return recordDao.selectList(queryWrapper);
    }
}
